unit frmMain1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, CategoryButtons, ComCtrls, ExtCtrls, ActnList,
  PlatformDefaultStyleActnCtrls, ActnMan, StdCtrls, ToolWin, ActnCtrls,
  ActnColorMaps;

type
  TForm1 = class(TForm)
    ActionManager1: TActionManager;
    actStart: TAction;
    actStop: TAction;
    actTrackEvent: TAction;
    actClearLog: TAction;
    actExit: TAction;
    actTrackEventValue: TAction;
    actTrackEventStart: TAction;
    actTrackEventStop: TAction;
    actTrackEventCancel: TAction;
    txtLog: TMemo;
    ActionToolBar1: TActionToolBar;
    ActionToolBar2: TActionToolBar;
    ActionToolBar3: TActionToolBar;
    ActionToolBar5: TActionToolBar;
    XPColorMap1: TXPColorMap;
    actTrackLog: TAction;
    actTrackException: TAction;
    actTrackExceptions: TAction;
    procedure actStartExecute(Sender: TObject);
    procedure actStopExecute(Sender: TObject);
    procedure actTrackEventExecute(Sender: TObject);
    procedure actClearLogExecute(Sender: TObject);
    procedure actExitExecute(Sender: TObject);
    procedure actTrackInstallationExecute(Sender: TObject);
    procedure actTrackUninstallationExecute(Sender: TObject);
    procedure actTrackEventValueExecute(Sender: TObject);
    procedure actTrackEventStartExecute(Sender: TObject);
    procedure actTrackEventStopExecute(Sender: TObject);
    procedure actTrackEventCancelExecute(Sender: TObject);
    procedure actTrackExceptionsExecute(Sender: TObject);
    procedure actTrackExceptionExecute(Sender: TObject);
    procedure actTrackLogExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    fTrackingExceptions: boolean;
    procedure dmLog(aLogMsg : string);
  public
  end;

var
  Form1: TForm1;

implementation

uses
  DeskMetricsDynamic;

{$R *.dfm}

const
  FAPPID : PWideChar = '<your application id here>';
  FAPPVER : PWideChar = '1.0';

procedure TForm1.actClearLogExecute(Sender: TObject);
begin
  txtLog.Lines.Clear;
end;

procedure TForm1.actExitExecute(Sender: TObject);
begin
  Close;
end;

procedure TForm1.actStartExecute(Sender: TObject);
begin
  if DeskMetricsStart(FAPPID, FALSE, FALSE) then
    dmLog('Started')
  else
    dmLog('Start Failed');
end;

procedure TForm1.actStopExecute(Sender: TObject);
begin
  if DeskMetricsStop then
    dmLog('Stopped')
  else
    dmLog('Stop Failed');
end;

procedure TForm1.actTrackEventCancelExecute(Sender: TObject);
begin
  DeskMetricsTrackEventCancel('Category1', 'Event3');
  dmLog('Event Cancel');
end;

procedure TForm1.actTrackEventExecute(Sender: TObject);
begin
  DeskMetricsTrackEvent('Category1', 'EventName1');
  dmLog('Event Tracked');
end;

procedure TForm1.actTrackEventStartExecute(Sender: TObject);
begin
  DeskMetricsTrackEventStart('Category1', 'Event3');
  dmLog('Event Start');
end;

procedure TForm1.actTrackEventStopExecute(Sender: TObject);
begin
  DeskMetricsTrackEventStop('Category1', 'Event3');
  dmLog('Event Stop');
end;

procedure TForm1.actTrackEventValueExecute(Sender: TObject);
begin
  DeskMetricsTrackEventValue('Category1', 'EventName2', 'EventValue1');
  dmLog('Event Value');
end;

procedure TForm1.actTrackExceptionExecute(Sender: TObject);
begin
  DeskMetricsTrackException('ExceptionMessage', 'ExceptionClass');
end;

procedure TForm1.actTrackExceptionsExecute(Sender: TObject);
begin
  fTrackingExceptions := not fTrackingExceptions;
  actTrackExceptions.Checked := fTrackingExceptions;
  DeskMetricsTrackExceptions(fTrackingExceptions);
end;

procedure TForm1.actTrackInstallationExecute(Sender: TObject);
begin
  DeskMetricsTrackInstallation(FAPPID, FAPPVER, FALSE);
  dmLog('Installation');
end;

procedure TForm1.actTrackLogExecute(Sender: TObject);
begin
  DeskMetricsTrackLog('This is a log message');
end;

procedure TForm1.actTrackUninstallationExecute(Sender: TObject);
begin
  DeskMetricsTrackUninstallation(FAPPID, FAPPVER, FALSE);
  dmLog('Uninstallation');
end;

procedure TForm1.dmLog(aLogMsg: string);
begin
  txtLog.lines.add(format('%s: %s', [FormatDateTime('yyyy-mmm-dd hh:nn', now), aLogMsg]));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  fTrackingExceptions := FALSE;
  actTrackExceptions.Checked := fTrackingExceptions;
end;

end.
